import cv2

image = cv2.imread('../temp/image.jpg')
if image is None:
    print("Cannot read image file")
    exit(-1)

angle = 30
center = (image.shape[1] // 2, image.shape[0] // 2)
rotated_mat = cv2.getRotationMatrix2D(center, angle, 1.0)

# Determine bounding rectangle, necessary to avoid clipping
bbox = cv2.warpAffine(image, rotated_mat, (image.shape[1], image.shape[0]))
rotated_mat[0, 2] += (bbox.shape[1] - image.shape[1]) / 2
rotated_mat[1, 2] += (bbox.shape[0] - image.shape[0]) / 2

rotated_image = cv2.warpAffine(image, rotated_mat, (bbox.shape[1], bbox.shape[0]))

cv2.imwrite('rotated_image.jpg', rotated_image)